package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.NoteCollection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoteCollectionRepository extends JpaRepository<NoteCollection, String> {
    ///根据noteId和userId查询是否已经收藏
    NoteCollection findOneByNoteIdAndUserId(String noteId, String userId);

    //根据userId查询所有的noteId
    @Query(value = "select n.noteId from NoteCollection n where n.userId = :userId")
    List<String> findNoteIdByUserId(@Param("userId") String userId);

    @Query(value = "select count(a) from NoteCollection a where a.noteId = :id ")
    Integer countAllByNoteId(@Param("id") String id);
}
